package com.own.core.html.tabs;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.wicket.AttributeModifier;
import org.apache.wicket.model.Model;

import com.own.app.OwnApp;
import com.own.app.OwnSession;
import com.own.core.html.panel.OwnPanel;
import com.own.core.object.admin.User;
import com.own.core.object.admin.Group; 
import com.own.core.object.admin.Role;
import com.own.core.object.admin.pages.Page;


import com.own.core.operation.DbOperation;

public class SubTab extends OwnPanel {
	Page mainPage;

	public SubTab(String id) {

		super(id);

	}


	public void initPanel() {
		setDefaultModel(new Model("subtab"));
		Map paraMap = new HashMap();
		paraMap.put("mainPageName", mainPage.getName());
		User user = ((OwnSession) getSession()).getUser();
		paraMap.put("userId",user.getId());
		
		List subMenu = DbOperation.getME()
				.executeNamedQuery("page.loadSubPage",paraMap);

	

		List tabs = new ArrayList();

		for (Object obj : subMenu) {
			try {
				Page page = (Page) obj;
				tabs.add(new OwnAbstractTab(page));
			} catch (Exception e) {
				e.printStackTrace();
			}
		}

			
		
		OwnAjaxTabbedPanel subTab = new OwnAjaxTabbedPanel("subtabs", tabs);
		subTab.add(new AttributeModifier("class", true, getDefaultModel()));
		this.add(subTab);

	}


	public Page getMainPage() {
		return mainPage;
	}


	public void setMainPage(Page mainPage) {
		this.mainPage = mainPage;
	}
 

}
